//
//  WYCRepaymentController.m
//  信用卡管理
//
//  Created by 中企互联 on 2017/11/14.
//  Copyright © 2017年 李胜军. All rights reserved.
//智能还款

#import "WYCIntelligentMoneyController.h"
#import "MyTextField.h"
#import "WYCSeeBillModel.h"
#import "LDCalendarView.h"
#import "NSDate+extend.h"
#import "WYCRepayModel.h"
#import "WYCTRepayCell.h"
#import "WYCSelectionPlanController.h"
#import "WYCPreviewViewController.h"
#import "repayModel.h"
#import "WYCPlanModel.h"
#import "WYCPlandetaiLCell.h"
#import "amountModel.h"
#import "WYCArgeeViewController.h"
#import "OYRPopOption.h"
#import "WYCHandBillController.h"
#import "WYCBillController.h"
#import "UIViewController+HUD.h"
#import "MyTextField.h"
@interface WYCIntelligentMoneyController ()<UITableViewDelegate,UITableViewDataSource,WYCSelectionPlanDelegate>
{
    
   int  summer;
    
    int maxNum;
    UILabel * backLabel;
    
    double string;
}
@property(nonatomic,strong) UILabel * typelabel;

@property (nonatomic, strong)LDCalendarView *calendarView;//日历控件
@property (nonatomic, strong)NSMutableArray *seletedDays;//选择的日期
@property (nonatomic, strong)NSMutableArray *dataArray;//数据数组

@property (nonatomic, copy)NSString *showStr;

/** planID*/
@property(nonatomic,strong)NSString * planID;

/** 时间*/
@property(nonatomic,strong)UILabel * timeLbel;

/** 模型赋值*/
@property(nonatomic,strong)WYCSeeBillModel * seeBillModel;


@property(nonatomic,strong)UITableView * tableView;

@property(nonatomic,strong)UITextField *repayTextField;


@property (nonatomic,strong) NSMutableArray *repayarray;

@property (nonatomic,strong) NSMutableArray *datearray;
@property (nonatomic,strong) NSMutableArray *poundagearray;

@property (nonatomic,strong) NSMutableArray *detArr;

@property (nonatomic,strong) WYCRepayModel *repaymodel;

/** 银行图标*/
@property(nonatomic,strong)UIImageView * bankImageView;

/** 顶部View */
@property (nonatomic,strong) UIView *topView;

/** 顶部View */
@property (nonatomic,strong) UIView *bigtopView;


/** 银行名称*/
@property (nonatomic,strong)UILabel * banklabel;


//加号
@property (nonatomic,strong) UIButton  *addButton;

//减号
@property (nonatomic,strong) UIButton  *rustButton;

//日历
@property (nonatomic,strong) UIButton  *riliButton;

@property (nonatomic,strong) UIButton  *planbtn;

@property (nonatomic,strong)UILabel * staylabel;

/** 本期账单余额*/
@property (nonatomic,strong)UILabel * balancelabel;


/** 日期*/
@property(nonatomic,strong)UITextField *daylabel;

/** UILabel * backLabel*/
@property(nonatomic,strong)UILabel * backLabel;
@property(nonatomic ,strong)UITextField *money;
@property(nonatomic ,strong)UITextField *balance;
@property(nonatomic,strong)UITextField *rili;
@property(nonatomic,strong)UITextField *plan;


@end

@implementation WYCIntelligentMoneyController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = WYCbgColor;
    _poundagearray = [[NSMutableArray alloc]init];
    self.datearray = [NSMutableArray new];
    self.dataArray  = [NSMutableArray new];
    
    //Nav
    [self setupNav];
    
    //请求
    [self setupRequster];
    
    self.repayarray = [NSMutableArray new];
    _datearray = [[NSMutableArray alloc]init];
    
    
    
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test) name:@"TextField" object:nil];
    
    WYCSelectionPlanController * selection = [[WYCSelectionPlanController alloc] init];
    selection.Delegate = self;
    
    //头部界面创建
    //    [self setupCreat];
}



- (NSString *)showStr {
    NSMutableString *str = [NSMutableString string];
    
    [str appendString:@""];
    //从小到大排序
    [self.seletedDays sortUsingComparator:^NSComparisonResult(NSNumber *obj1, NSNumber *obj2) {
        return [obj1 compare:obj2];
    }];
    for (NSNumber *interval in self.seletedDays) {
        NSString *partStr = [NSDate stringWithTimestamp:interval.doubleValue/1000.0 format:@"yyyy-MM-dd"];
        [str appendFormat:@"%@,",partStr];
        [self.tableView reloadData];
    }
    return [str copy];
}

#pragma make -------->>请求数据
- (void)setupRequster{
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    params[@"cardId"] = self.cardId;
    params[@"token"] = [WYCAccountTool unarchivetoken];
    
    [HttpTool POST:creditcarddetails params:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            NSDictionary * dict = responseObject[@"result"];
            self.seeBillModel = [WYCSeeBillModel mj_objectWithKeyValues:dict];
        }else{
            
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
            [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
            [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
        }
        
        //界面
        [self setupCreat];
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}

#pragma make ---------->>头部界面创建
- (void)setupCreat{
    //蓝色
    UIImageView * backView = [[UIImageView alloc] init];
    backView.frame = CGRectMake(0, NavHeight, ScreenWidth, 200);
    backView.backgroundColor = wycMain;
    [self.view addSubview:backView];
    
    
    //白色
    UIImageView * backView2 = [[UIImageView alloc] init];
    backView2.frame = CGRectMake(10, 20, ScreenWidth-20, 170);
    backView2.layer.cornerRadius = 30 * px;
    [backView addSubview:backView2];
    UIImageView * bankImage = [[UIImageView alloc] init];
    bankImage.frame = CGRectMake(20, 20, 25, 25);
    //    bankImage.layer.cornerRadius = 30 * px;
    [backView2 addSubview:bankImage];
    
    NSInteger bankid = [self.bankid integerValue];
    
    switch (bankid) {
        case 10000://招商银行
            backView2.image = [UIImage imageNamed:@"bank_bg_zhaoshang"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_zs"];
            break;
        case 10001://工商银行
            backView2 .image = [UIImage imageNamed:@"bank_bg_gongshang"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_gs"];
            
            break;
        case 10002://农业银行
            backView2.image = [UIImage imageNamed:@"bank_bg_ny"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_ny"];
            
            break;
        case 10003://  建设银行
            backView2.image = [UIImage imageNamed:@"bank_bg_jianshe"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_js"];
            
            break;
        case 10004://中国银行
            backView2.image = [UIImage imageNamed:@"bank_bg_zhongguo"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_zy"];
            
            break;
        case 10005:  //浦发银行
            backView2.image = [UIImage imageNamed:@"bank_bg_pufa"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_pf"];
            
            break;
        case 10006:  //交通银行
            backView2.image = [UIImage imageNamed:@"bank_bg_jiaotong"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_jt"];
            
            break;
        case 10007:  //民生银行
            backView2.image = [UIImage imageNamed:@"bank_bg_minsheng"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_ms"];
            
            break;
        case 10009:  //广东发展银行
            backView2.image = [UIImage imageNamed:@"bank_bg_gf"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_gf"];
            
            break;
        case 10010:  //中信银行
            backView2.image = [UIImage imageNamed:@"bank_bg_zhongxin"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_zx"];
            
            break;
        case 10011:  //  华夏银行
            backView2.image = [UIImage imageNamed:@"bank_bg_hx"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_hx"];
            
            break;
        case 10012:  //  兴业银行
            backView2.image = [UIImage imageNamed:@"bank_bg_xingye"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_xy"];
            
            break;
        case 10014:  //  江苏银行
            backView2.image = [UIImage imageNamed:@"bank_bg_jiangsu"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_gs"];
            
            break;
        case 10016:  //  北京银行
            backView2.image = [UIImage imageNamed:@"bank_bg_bj"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_bj"];
            
            break;
        case 10020://10020  光大银行
            backView2.image = [UIImage imageNamed:@"bank_bg_gd"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_gd"];
            
            break;
        case  10024://平安银行
            backView2.image = [UIImage imageNamed:@"bank_bg_pinan"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_pa"];
            
            break;
        case 10027:  //上海银行
            backView2.image = [UIImage imageNamed:@"bank_bg_shanghai"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_sh"];
            
            break;
        case  10028://  中国邮政储蓄银行
            backView2.image = [UIImage imageNamed:@"bank_bg_youzheng"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_yz"];
            
            break;
            
        default:
            backView2.image = [UIImage imageNamed:@"icon_other_bank"];
            bankImage.image = [UIImage imageNamed:@"bank_icon_gs"];
            
            break;
    }
    UILabel *titleStr = [[UILabel alloc] init];
    titleStr.frame = CGRectMake( bankImage.frame.size.width+bankImage.frame.origin.x+20,20, backView2.width-20, 20);
    titleStr.text =  [NSString stringWithFormat:@"%@",self.bankName];
    titleStr.textAlignment = NSTextAlignmentLeft;
    titleStr.textColor = [UIColor blackColor];
    titleStr.font = [UIFont systemFontOfSize:15];
    [backView2 addSubview:titleStr];
    
    UILabel *benqizhangdan = [[UILabel alloc] init];
    benqizhangdan.frame = CGRectMake(20, CGRectGetMaxY(titleStr.frame) + 10, titleStr.width-10, 20);
    benqizhangdan.text = @"本期账单（2018.1）";
    benqizhangdan.textAlignment = NSTextAlignmentLeft;
    benqizhangdan.textColor = [UIColor grayColor];
    benqizhangdan.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:benqizhangdan];
    
    UILabel * balancelabel = [[UILabel alloc] init];
    balancelabel.frame = CGRectMake(20,benqizhangdan.frame.size.height+benqizhangdan.frame.origin.y+10 , 600  * px, 70 * px);
    NSString * billAmount = [NSString stringWithFormat:@"%.1f",[self.billAmount doubleValue]];
    balancelabel.text = billAmount;
    balancelabel.textColor = wycMain;
    balancelabel.textAlignment = NSTextAlignmentLeft;
    balancelabel.font = [UIFont systemFontOfSize:25];
    [backView2 addSubview:balancelabel];
    
    
    //账单日
    UILabel *Statementlabel = [[UILabel alloc] init];
    Statementlabel.frame = CGRectMake(0, balancelabel.frame.size.height+balancelabel.frame.origin.y+10, backView2.width / 4, 50 * px);
    Statementlabel.text = @"账单日";
    Statementlabel.textAlignment = NSTextAlignmentCenter;
    Statementlabel.textColor = [UIColor grayColor];
    Statementlabel.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Statementlabel];
    
    
    UILabel *Statement = [[UILabel alloc] init];
    Statement.frame = CGRectMake(Statementlabel.x, CGRectGetMaxY(Statementlabel.frame) , Statementlabel.width, Statementlabel.height);
    Statement.text = [NSString stringWithFormat:@"%@",self.billDate];
    Statement.textAlignment = NSTextAlignmentCenter;
    Statement.textColor = [UIColor blackColor];
    Statement.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Statement];
    
    //还款日
    UILabel *Repaymentlabel = [[UILabel alloc] init];
    Repaymentlabel.frame = CGRectMake(backView2.width / 4, Statementlabel.y, Statementlabel.width, Statementlabel.height);
    Repaymentlabel.text = @"还款日";
    Repaymentlabel.textAlignment = NSTextAlignmentCenter;
    Repaymentlabel.textColor = [UIColor grayColor];
    Repaymentlabel.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Repaymentlabel];
    
    
    UILabel *Repayment = [[UILabel alloc] init];
    Repayment.frame = CGRectMake(Repaymentlabel.x, CGRectGetMaxY(Repaymentlabel.frame), Statementlabel.width, Statementlabel.height);
    NSString * dueDate = [NSString stringWithFormat:@"%@",self.dueDate];
    Repayment.text = dueDate;
    Repayment.textColor = [UIColor blackColor];
    Repayment.textAlignment = NSTextAlignmentCenter;
    Repayment.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Repayment];
    
    
    //免息期
    UILabel *Gracelabel = [[UILabel alloc] init];
    Gracelabel.frame = CGRectMake(backView2.width / 2, Statementlabel.y, Statementlabel.width, Statementlabel.height);
    Gracelabel.text = @"免息期";
    Gracelabel.textAlignment = NSTextAlignmentCenter;
    Gracelabel.textColor = [UIColor grayColor];
    Gracelabel.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Gracelabel];
    
    
    UILabel *Grace = [[UILabel alloc] init];
    Grace.frame = CGRectMake(Gracelabel.x, CGRectGetMaxY(Gracelabel.frame) , Statementlabel.width, Statementlabel.height);
    NSString * gracePeriod = [NSString stringWithFormat:@"%@",self.gracePeriod];
    Grace.text = gracePeriod;
    Grace.textColor = [UIColor blackColor];
    Grace.textAlignment = NSTextAlignmentCenter;
    Grace.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Grace];
    
    
    
    //总额度
    UILabel *Totallabel = [[UILabel alloc] init];
    Totallabel.frame = CGRectMake(backView2.width / 4 * 3, Statementlabel.y, Statementlabel.width, Statementlabel.height);
    Totallabel.text = @"总额度";
    Totallabel.textAlignment = NSTextAlignmentCenter;
    Totallabel.textColor = [UIColor grayColor];
    Totallabel.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Totallabel];
    
    
    UILabel *Total = [[UILabel alloc] init];
    Total.frame = CGRectMake(Totallabel.x, CGRectGetMaxY(Totallabel.frame), Statementlabel.width, Statementlabel.height);
    Total.textAlignment = NSTextAlignmentCenter;
    NSString * creditLine = [NSString stringWithFormat:@"%.1f",[self.creditLine doubleValue]];
    Total.text = creditLine;
    Total.textColor = [UIColor blackColor];
    Total.font = [UIFont systemFontOfSize:SmallFont];
    [backView2 addSubview:Total];

    NSArray  *imageArr = @[@"还款金额：",@"卡内余额：",@"还款天数：",@"消费日期：",@"消费计划："];
    NSArray  *titleArr = @[@"请输入还款金额",@"请输入卡内余额",@"",@"选择还款日期",@"选择消费计划"];
    
    for (int i = 0; i<imageArr.count; i++)
    {
        
        /** 顶部View */
        self.topView = [[UIView alloc] init];
        self.topView.frame = CGRectMake(10,( CGRectGetMaxY(backView.frame)+10)+60*i, ScreenWidth-20, 50);
        self.topView.userInteractionEnabled =YES;
        self.topView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:self.topView];
        
        UILabel  *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
        title.text =[imageArr objectAtIndex:i];
        title.textColor = [UIColor blackColor];
        [self.topView addSubview:title];
        
        /** 输入框*/
        self.repayTextField = [[MyTextField alloc] init];
        self.repayTextField.frame = CGRectMake( 110, 10, _topView.width / 2, 30);
        self.repayTextField.enabled = NO;
        self.repayTextField.keyboardType = UIKeyboardTypeNumberPad;
        self.repayTextField.placeholder = [titleArr objectAtIndex:i];
        self.repayTextField.tintColor = wycMain;
        self.repayTextField.font = [UIFont systemFontOfSize:50 * px];
        [self.topView addSubview:self.repayTextField];
        if (i==0) {
            self.repayTextField.enabled = YES;
           _money = self.repayTextField;
            self.repayTextField.placeholder = @"账单金额加手续费";
            [self.repayTextField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];

        }
        if (i==1) {
            self.repayTextField.enabled = YES;

            [ self.repayTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
            _balance = self.repayTextField;

        }
        if (i==2) {
            _daylabel = self.repayTextField;
            //-号按钮
            self.rustButton = [[UIButton alloc] init];
            self.rustButton.frame = CGRectMake(self.topView.width - 290 * px, 40 * px, 80 * px, 80 * px);
            [self.rustButton setImage:[UIImage imageNamed:@"icon_count_js"] forState:UIControlStateNormal];
            
            [self.rustButton addTarget:self action:@selector(reduceButtonClick) forControlEvents:UIControlEventTouchUpInside];

            [self.topView addSubview:self.rustButton];
            
            //+号按钮
            self.addButton = [[UIButton alloc] init];
            self.addButton.frame = CGRectMake(CGRectGetMaxX(self.rustButton.frame) + 40 * px,40 * px, 80 * px, 80 * px);
            [self.addButton setImage:[UIImage imageNamed:@"icon_count_zj"] forState:UIControlStateNormal];
            [self.addButton addTarget:self action:@selector(addButtonClick) forControlEvents:UIControlEventTouchUpInside];
            [self.topView addSubview:self.addButton];
            
        }
      
        if (i == 3) {
            //日历
            self.riliButton = [[UIButton alloc] init];
            self.riliButton .frame = CGRectMake(110, 40 * px, 180, 40);
            [self.riliButton addTarget:self action:@selector(CalculatorButtonClick) forControlEvents:UIControlEventTouchUpInside];
            [self.topView addSubview:self.riliButton];
            _rili = self.repayTextField;
        }
        if (i == 4) {
            self.planbtn = [[UIButton alloc] init];
            self.planbtn .frame = CGRectMake(110, 40 * px, 180, 40);
            [self.planbtn addTarget:self action:@selector(loadPlan) forControlEvents:UIControlEventTouchUpInside];
            [self.topView addSubview:self.planbtn];
            _plan = self.repayTextField;
            
        }
      
        
    }
    
    UIButton * returnButton = [[UIButton alloc] init];
    returnButton.frame = CGRectMake( 40 * px,  ScreenHeight-90, ScreenWidth - 80 * px, 150 * px);
    returnButton.backgroundColor = wycMain;
    [returnButton setTitle:@"生成智能还款计划" forState:UIControlStateNormal];
    [returnButton addTarget:self action:@selector(returnButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [returnButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:returnButton];
    
    //用户须知的按钮
    UIButton * userAgreeBtn = [[UIButton alloc] init];
    userAgreeBtn.titleLabel.font = [UIFont systemFontOfSize:43 * px];
    userAgreeBtn.frame = CGRectMake(returnButton.x + 80,CGRectGetMaxY(returnButton.frame) + 20 * px,20, 20);
    [userAgreeBtn setImage:[UIImage imageNamed:@"agree"] forState:UIControlStateNormal];
    [self.view addSubview:userAgreeBtn];
    
    UILabel * PromptLable = [[UILabel alloc] init];
    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:SmallFont];
    NSString * str = @"我已阅读并同意";
    PromptLable.font = fnt;
    PromptLable.x = userAgreeBtn.x + 30;
    PromptLable.y = CGRectGetMaxY(returnButton.frame) + 30 * px;
    CGSize PromptLableSize = [str sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    PromptLable.text = str;
    PromptLable.textColor = WYCRGBColor(157, 157, 157);
    PromptLable.frame = CGRectMake(PromptLable.x, PromptLable.y, PromptLableSize.width, PromptLableSize.height);
    [self.view addSubview:PromptLable];
    
    
    
    //用户须知的按钮
    UIButton * userAgreement = [[UIButton alloc] init];
    [userAgreement setTitle:@"《用户协议》" forState:UIControlStateNormal];
    userAgreement.titleLabel.font = [UIFont systemFontOfSize:43 * px];
    userAgreement.frame = CGRectMake(CGRectGetMaxX(PromptLable.frame), PromptLable.y, PromptLable.width + 90 * px, PromptLable.height);
    userAgreement.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [userAgreement setTitleColor:wycMain forState:UIControlStateNormal];
    [userAgreement addTarget:self action:@selector(pressAgree) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:userAgreement];
}

-(void)textFieldDidChange :(UITextField *)theTextField{
    
    NSLog( @"text changed: %@  %@", _money.text,_balance.text);
    
   
    if (_money.text.length == 0) {
        [self showToast:@"还款金额不能为空"];
        
        return;
    }
    else if (_balance.text.length == 0) {
        
        [self showToast:@"卡内金额不能为空"];
        
        return;
    }
    
  else  if (theTextField == _balance) {
      NSLog(@"进来了");
    int repaymentintValue = [_money.text intValue];
    //卡内余额
    int balanceintValue = [_balance.text intValue];
    
    int onestr = repaymentintValue *0.06 ;
    int str = balanceintValue;
    
    if (str < onestr ) {
        [self showToast:@"余额不能低于的6%"];
        
        return;
    }
           double mo = [_money.text doubleValue];
            double str2 = [[WYCAccountTool unarchiverepaymentRate] doubleValue];
    
            string = (mo * str2) / 100;
    
            backLabel.text = [NSString stringWithFormat:@"本期账单消费手续费：%.2f元",string];
            double  dascount = repaymentintValue / balanceintValue - string;
    
            NSString * stringDday = [NSString stringWithFormat:@"%.2f",dascount];
    
            NSArray * dayarray = [stringDday componentsSeparatedByString:@"."];
            if (dayarray[1] != 0) {
                double sm = [dayarray[0] intValue] + 1;
                double i =  (balanceintValue - string - sm) * 1;
                double n = repaymentintValue / i;
                NSString * nStr = [NSString stringWithFormat:@"%.2f",n];
                NSArray * narr = [nStr componentsSeparatedByString:@"."];
    
                if (narr[1] != 0) {
                    summer = [narr[0] intValue] + 1;
                    _daylabel.text = [NSString stringWithFormat:@"%d",summer];
                }
    
            }else{
                summer = [dayarray[0] intValue];
                _daylabel.text = [NSString stringWithFormat:@"%d",summer];
    
            }
    }
    
}
#pragma make ----------->>Nav
- (void)setupNav{
    
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    NSString *title =  [NSString stringWithFormat:@"%@(%@)",self.bankName,self.lastNumber];
    self.navigationItem.title = title;
    //右侧按钮
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"Three" hight:@"Three" target:self action:@selector(ThreeClick:)];
    
}
-(void)loadPlan
{
    WYCSelectionPlanController * SetUsercontroller = [[WYCSelectionPlanController alloc] init];
    SetUsercontroller.bankId = self.seeBillModel.bankId;
    SetUsercontroller.Delegate = self;
    
    int repaymentintValue = [_money.text intValue];
    
    int repaymentintValue2 = [_daylabel.text intValue];
    
    int str = repaymentintValue / repaymentintValue2;
    
    SetUsercontroller.dailyAmount = [NSString stringWithFormat:@"%d",str];
    
    SetUsercontroller.balance = [NSString stringWithFormat:@"%d",repaymentintValue];
    
    [self.navigationController pushViewController:SetUsercontroller animated:NO];
    
}
- (void)ThreeClick:(UIButton *)optionButton{
    
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    CGRect frame = [optionButton convertRect:optionButton.bounds toView:window];
    
    
    OYRPopOption *s = [[OYRPopOption alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    
    s.option_optionContents = @[@"隐藏该卡", @"手动账单"];
    // 使用链式语法直接展示 无需再写 [s option_show];
    [[s option_setupPopOption:^(NSInteger index, NSString *content) {
        
        
        if (index == 0) {
            
            NSMutableDictionary * params = [NSMutableDictionary dictionary];
            params[@"token"] = [WYCAccountTool unarchivetoken];
            params[@"cardId"] = self.cardId;
            params[@"isHideCard"] = @"1";
            [HttpTool POST:creditcardsetHideCard params:params success:^(NSURLSessionDataTask *task, id responseObject) {
                
                if ([[responseObject objectForKey:@"code"] intValue] == 0) {
                    
                    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"成功"];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
                    [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
                    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
                    
                    for (UIViewController *controller in self.navigationController.viewControllers) {
                        if ([controller isKindOfClass:[WYCBillController class]]) {
                            [self.navigationController popToViewController:controller animated:YES];
                            break;
                        }
                    }
                    WYCBillController *SendDrugVC = [[WYCBillController alloc]init];
                    [self.navigationController popToViewController:SendDrugVC animated:YES];
                    
                }else{
                    
                    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
                    [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
                    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
                    
                }
                
            } fail:^(NSURLSessionDataTask *task, NSError *error) {
                
                [SVProgressHUD showImage:[UIImage imageNamed:@""] status:Failed];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
                [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
                [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
                
            }];
            
        }else{
            
            WYCHandBillController * OperationBll = [[WYCHandBillController alloc] init];
            [self.navigationController pushViewController:OperationBll animated:NO];
            
        }
        
    } whichFrame:frame animate:YES] option_show];
    
}

//用户协议
-(void)pressAgree
{
    WYCArgeeViewController  *agree = [[WYCArgeeViewController alloc]init];
    [self.navigationController pushViewController:agree animated:YES];
}


#pragma make --------->>日历选择
- (void)CalculatorButtonClick{
    
    WYCLogFunc;

    int huankuan = [_money.text intValue];
    //卡内余额
    int balanceintValue = [_balance.text intValue];

    int onestr = huankuan *0.06 ;
    int str = balanceintValue;

    if (str < onestr ) {
        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"余额不能低于还款金额的6%"];
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
        [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
        return;
    }else{
    if (!_calendarView) {
        _calendarView = [[LDCalendarView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,SCREEN_HEIGHT)];
        [self.view addSubview:_calendarView];
        
        __weak typeof(self) weakSelf = self;
        _calendarView.complete = ^(NSArray *result) {
            if (result.count != 0) {
                weakSelf.seletedDays = [result mutableCopy];
//                WYCRepayModel * model3 = weakSelf.repayarray[3];
                NSString * str = [NSString stringWithFormat:@"%@",weakSelf.showStr];
                NSString *b = [str substringToIndex:[str length]-1];
                NSLog(@"选择%@",b);
                _rili.text = b;
                
            }
        };
    }
    [self.calendarView show];
    }
}


#pragma make --------->>加号按钮
- (void)addButtonClick{
    WYCLogFunc;
    
    summer = [_daylabel.text intValue];
    summer++;
    _daylabel.text = [NSString stringWithFormat:@"%d",summer];

    
    
}

#pragma make --------->>减号按钮
- (void)reduceButtonClick{
    
    summer = [_daylabel.text intValue];
    if (summer == 0) {
        return;
    }
    summer--;
    _daylabel.text = [NSString stringWithFormat:@"%d",summer];

    
}

-(void)nextplan{
    WYCPreviewViewController  *preView = [[WYCPreviewViewController alloc]init];
    [self.navigationController pushViewController:preView animated:YES];
    
}
//生成智能还款计划
- (void)returnButtonClick{
   ;
    
    if (_money.text.length == 0) {
        [self showToast:@"还款金额不能为空"];
     
        return;
    }
   else if (_balance.text.length == 0) {
        
       [self showToast:@"卡内金额不能为空"];

        return;
    }
   
   else if (self.planID.length == 0) {
       [self showToast:@"消费计划不能为空"];

      
       return;
   }
    else{
    
   
        NSString * str = [NSString stringWithFormat:@"%@",self.showStr];
        NSString *b = [str substringToIndex:[str length]-1];
//        _daylabel.text = b;
        NSMutableDictionary * params = [NSMutableDictionary dictionary];
        params[@"token"] = [WYCAccountTool unarchivetoken];
        params[@"cardId"] = self.seeBillModel.cardId;
        params[@"amount"] = _money.text;
        params[@"balance"] = _balance.text;
        params[@"days"] = _daylabel.text;
        params[@"consumeDates"] = _rili.text;
        params[@"consumePlanId"] = self.planID;
        NSLog(@"params%@",params);
      
        [HttpTool POST:epaymentplan params:params success:^(NSURLSessionDataTask *task, id responseObject) {
            NSLog(@"");
            if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            
                WYCPreviewViewController  *preView = [[WYCPreviewViewController alloc]init];
                preView.parmDic = params;
                [self.navigationController pushViewController:preView animated:YES];
                
            }
            else
            {
                [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"已经有待创建计划"];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
                [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
                [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色

            }
            [self.tableView reloadData];
            
            
        } fail:^(NSURLSessionDataTask *task, NSError *error) {

            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"网络请求失败"];

        }];

    }
}

- (void)setDelegatemaxNumber:(NSString *)maxNumber setID:(NSString *)ID{
    NSString *strPlan = [NSString stringWithFormat:@"%@",maxNumber];
//    self.plan.placeholder = @"";
    self.plan.text = strPlan;
//    [self.planbtn setTitle:strPlan forState:UIControlStateNormal];
//    [self.planbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.planID = ID;
}
-(void)setupbank:(NSString *)strbank
{
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    params[@"token"] = [WYCAccountTool unarchivetoken];
    params[@"planNo"] = strbank;
    [HttpTool POST:epaymentplanbank params:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        WYCLog(@"-----------responseobject%@",responseObject);
        NSLog(@"计划创建返回信息%@",[responseObject objectForKey:@"msg"]);
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"计划创建成功"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
            [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
            [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
            [self.navigationController popViewControllerAnimated:YES];

        }
    
        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"计划创建失败"];
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
        [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
        [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色


    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}
#pragma make ---------->>进入控制器改变Nav颜色
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar setBarTintColor:wycMain];
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
    [self.navigationController.navigationBar setBarTintColor:wycMain];
}
- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end

